#include <iostream>
#include <cstring>
#include <cstdio>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int T, n, a[N], maxp, lst, ans = 0;
int co[N], vis[N];
void DFS(int i) {
    if (i == n + 1) {
        int lstr = 0, lstb = 0, res = 0;
        for (int i = 1; i <= n; i++) {
            if (co[i] == 1 && a[lstr] == a[i]) res += a[i];
            else if (co[i] == 2 && a[lstb] == a[i]) res += a[i];
            if (co[i] == 1) lstr = i;
            else lstb = i;
        }
        ans = max(ans, res);
    }
    else {
        co[i] = 1;
        DFS(i + 1);
        co[i] = 2;
        DFS(i + 1);
    }
}
signed main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while (T--) {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        ans = 0;
        DFS(1);
        cout << ans << '\n';
    }
    return 0;
}
